package com.ten.course.controller;

import com.ten.common.core.entity.EduCourseCollect;
import com.ten.common.core.vo.Result;
import com.ten.course.service.EduCourseCollectService;
import com.ten.course.vo.CourseShouCangVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author ：张成（3092211427@qq.com）
 * @date ：Created in 2022/12/26 14:20
 * @description：
 * @modified By：
 * @version:
 */
@RestController
@RequestMapping("/core/shoucangCourse")
@Api(tags = "课程收藏接口")
public class CollectController {

    @Autowired
    private EduCourseCollectService eduCourseCollectService;

    /**
     * 根据课程id和memberId查询member有没有收藏该课程
     *
     * @param eduCourseCollect 包含课程id和memberId
     * @return
     */
    @ApiOperation(value = "根据课程id和memberId查询member有没有收藏该课程")
    @PostMapping("findFavoriteCourse")
    public Result findFavoriteCourse(@RequestBody EduCourseCollect eduCourseCollect){
        return eduCourseCollectService.findFavoriteCourse(eduCourseCollect);
    }

    /**
     * 根据课程id和会员id添加收藏
     * @param eduCourseCollect
     * @return
     */
    @PostMapping("addFavoriteCourse")
    @ApiOperation(value = "根据课程id和会员id添加收藏")
    public Result addFavoriteCourse(@RequestBody EduCourseCollect eduCourseCollect){
        return eduCourseCollectService.addFavoriteCourse(eduCourseCollect);
    }

    @ApiOperation(value = "取消收藏")
    @PostMapping("deleteFavoriteCourse")
    public Result deleteFavoriteCourse(@RequestBody EduCourseCollect eduCourseCollect){
        return eduCourseCollectService.deleteFavoriteCourse(eduCourseCollect);
    }

    /**
     * 通过会员id查询所有收藏的信息
     * @param huiYuanId 会员id
     * @return
     */
    @ApiOperation(value = "通过会员id查询所有收藏的信息")
    @PostMapping("findFavoriteCourseById/{huiYuanId}")
    public Result<List<CourseShouCangVo>> findFavoriteCourseById(@PathVariable String huiYuanId){
        return eduCourseCollectService.findFavoriteCourseById(huiYuanId);
    }
}